import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;


/**
 * Created by Scott Tiger.
 * User: tomaszsocha
 * Date: 2010-05-05
 * Time: 13:27:36
 */
public class LaczenieItem extends JPanel{
    private  JPanel panel;
    private  JPanel panel2;

    public JComboBox getPrefyBox() {
        return prefyBox;
    }

    public JComboBox getSufyBox() {
        return sufyBox;
    }

    private  JPanel panelWynik;
    private  JButton newPref;
    private  JButton newSuf;
    private  JButton newItem;
    private  JButton nextButton;

    public  JComboBox prefyBox;
    public  JComboBox sufyBox;
    private  JComboBox prefyBox2;
    private  JComboBox sufyBox2;
    private  JComboBox itemBox;
    private  JComboBox itemBox2;
    private  JButton polaczButton;

    public Objeto getLaczeniaPrefy() {
        return laczeniaPrefy;
    }

    public Objeto getLaczeniaSufy() {
        return laczeniaSufy;
    }

    public Objeto getLaczeniaItem() {
        return laczeniaItem;
    }

    private  Objeto laczeniaPrefy;
    private  Objeto laczeniaSufy;
    private  Objeto laczeniaItem;

    public Objeto getLaczenia() {
        return laczenia;
    }

    private  Objeto laczenia;




    public LaczenieItem(String itemName,Boolean itemOnly) {


        try {
            laczeniaPrefy = new Objeto("bw/"+itemName+"WagaPref.csv","bw/"+itemName+"Prefy.csv");
            laczeniaSufy = new Objeto("bw/"+itemName+"WagaSuf.csv","bw/"+itemName+"Sufy.csv");
            laczeniaItem = new Objeto("bw/"+itemName+"Waga.csv","bw/"+itemName+".csv");
            laczenia = new Objeto("bw/"+itemName+"WagaPref.csv","bw/"+itemName+"Prefy.csv","bw/"+itemName+"WagaSuf.csv","bw/"+itemName+"Sufy.csv","bw/"+itemName+"Waga.csv","bw/"+itemName+".csv");
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            System.out.println("bw/"+itemName+"Waga.csv"+"bw/"+itemName+".csv");
        }


        prefyBox = new Prefix(itemName);
        sufyBox = new Sufix(itemName);
        prefyBox2 = new Prefix(itemName);
        sufyBox2 = new Sufix(itemName);
        panel = new JPanel();
        itemBox =  new ItemType(itemName);
        itemBox2 =  new ItemType(itemName);


        this.setLayout(new GridLayout(6,3,3,3));
        panel2 = new JPanel();
        panel2.add(prefyBox2);
        panel2.add(itemBox2);
        panel2.add(sufyBox2);
        panel.add(prefyBox);
        panel.add(itemBox);
        panel.add(sufyBox);





      Action polacz = new AbstractAction("Merge") {

          public void actionPerformed(ActionEvent actionEvent) {

              newPref.setText(laczeniaPrefy.polacz((String) prefyBox.getSelectedItem(),(String) prefyBox2.getSelectedItem()));
              newSuf.setText(laczeniaSufy.polacz((String) sufyBox.getSelectedItem(),(String) sufyBox2.getSelectedItem()));
              newItem.setText(laczeniaItem.polacz((String) itemBox.getSelectedItem(),(String) itemBox2.getSelectedItem()));
              panelWynik.setVisible(true);

              System.out.println(prefyBox.getSelectedItem() +" + " +prefyBox2.getSelectedItem()+ "-> " + newPref.getText());
              System.out.println(sufyBox.getSelectedItem() +" + " +sufyBox2.getSelectedItem()+ "-> " + newSuf.getText());
              System.out.println(itemBox.getSelectedItem() +" + " +itemBox2.getSelectedItem()+ "-> " + newItem.getText());
          }
        };

       Action next = new AbstractAction("Next Merge") {

          public void actionPerformed(ActionEvent actionEvent) {

              prefyBox.setSelectedItem( newPref.getText());
              sufyBox.setSelectedItem(newSuf.getText());
              itemBox.setSelectedItem(newItem.getText());
              panelWynik.setVisible(true);
          }
        };



       polaczButton = new JButton(polacz);


        newPref = new JButton();

        newItem = new JButton();
        newItem.setText("koszulka");
        newSuf = new JButton();


        panelWynik = new JPanel();
        panelWynik.add(newPref);
        panelWynik.add(newItem);
        panelWynik.add(newSuf);
        nextButton = new JButton(next);
        panelWynik.add(nextButton);
        panelWynik.setVisible(false);
        this.add(panel);
        this.add(panel2);
        this.add(polaczButton);
        this.add(panelWynik);
        this.setName(itemName);

    }


}

 // Nowe pliki csv nalezy wrzucac /Users/tomaszsocha/svn/Bloodwars/out/production/Bloodwars zeby dzialalo w Idea
 // i do katalogu bw ze zrodlami zeby zassac je do jara ;)
 // /Users/tomaszsocha/svn/Bloodwars/bw

